
<link rel="stylesheet" href="/static/Admin/css/bootstrap-select.min.css">
<script src="/static/Admin/js/bootstrap-select.min.js"></script>
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h4 class="modal-title" id="ntModalLabel" type='{$request}'>{$title}</h4>
</div>

<div class="modal-body">
        <div class="row clearfix">
                <div class="col-md-12 column">
                  <div class="alert alert-dismissable alert-info">
                    <button type="button" class="close">×</button>
                     <p></p>
                    </div>
                </div>
               </div>
   <div class="row clearfix">
        <div class="col-md-12 column">
            <ul class="nav nav-tabs" role="tablist">
                <li role="presentation" class="active">
                    <a href="#zh" aria-controls="zh" role="tab" data-toggle="tab">{:lang('Chinese')}</a>
                </li>
                <li role="presentation">
                    <a href="#en" aria-controls="en" role="tab" data-toggle="tab">{:lang('English')}</a>
                </li>
                <li role="presentation">
                    <a href="#pt" aria-controls="pt" role="tab" data-toggle="tab">{:lang('Portuguese')}</a>
                </li>
            </ul>


            <form class="tab-content formbox">
                <div role="tabpanel" class="tab-pane active" id="zh">
                    <table class="table table-striped table-hover ntTable" style="padding-top:0">
                            <tbody>
                                <tr>
                                    <td>{:lang("top_rating")}<span class="required"></span></td>
                                    <td>
                                        <div class="input-group" style="width: 200px;">
                                            <select name="pclass_zh" class="selectpicker"  data-live-search="true">
                                                
                                                {if isset($catedata)}
                                                    <option value="0" selected>
                                                        {:lang("top_rating")}
                                                    </option>
                                                    {volist name="catedata" id="vo"}

                                                        {if isset($editParent_id) }
                                                            {if condition="$editParent_id eq $vo.id"}
                                                                <option value="{$vo.id}" selected>
                                                                    {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_zh)}
                                                                </option>
                                                            {else /}
                                                                <option value="{$vo.id}" >
                                                                    {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_zh)}
                                                                </option>
                                                            {/if}
                                                        {else /}
                                                            <option value="{$vo.id}" >
                                                                {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_zh)}
                                                            </option>
                                                        {/if}
                                                    {/volist}
                                                {/if}

                                                {notempty name="$addChild"}
                                                    <option value="{$addChild.id}">
                                                        {$addChild.name_zh}
                                                    </option>
                                                {/notempty}
                                            </select>
                                        </div>
                                    </td>
                                </tr>
                                <tr>
                                    <td>{:lang("product_category_name")}<span class="required"></span></td>
                                    <td>
                                        {if isset($detail)}
                                            <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_zh" value="{$detail.name_zh}">
                                            <input type="hidden" class="classdid" name="clasdid_zh" value="{$detail.id}">
                                        {else /}
                                            <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_zh" value="">
                                        {/if}
                                    </td>
                                </tr>
                                <tr>
                                    <td>{:lang('status')}</td>
                                    <td  class="status">
                                        <label class="checkbox-inline">
                                            <input type="radio" name="status_zh" value="1" {if isset($detail)}{if ($detail.status ==1)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if} > {:lang('normal')}
                                        </label>
                                        <label class="checkbox-inline">
                                            <input type="radio" name="status_zh" value="3" {if isset($detail)}{if ($detail.status ==3)}checked{/if}{/if}> {:lang("hide")}
                                        </label>
                                        <label class="checkbox-inline">
                                            <input type="radio" name="status_zh" value="4" {if isset($detail)}{if ($detail.status ==4)}checked{/if}{/if}> {:lang("off_the_shelf")}
                                        </label>
                                        <label class="checkbox-inline">
                                            <input type="radio" name="status_zh" value="2" {if isset($detail)}{if ($detail.status ==2)}checked{/if}{/if}> {:lang('delete')}
                                        </label>
                                    </td>
                                </tr>
                               <!--  <tr>
                                    <td>{:lang('universal')}</td>
                                    <td class="linkage">
                                        <label class="checkbox-inline">
                                            <input type="radio" name="general_zh" value="1" {if isset($detail)}{if ($detail.is_public ==1)}checked{/if}{/if}> {:lang('yes')}
                                        </label>
                                        <label class="checkbox-inline">
                                            <input type="radio" name="general_zh" value="2" {if isset($detail)}{if ($detail.is_public ==2)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if}> {:lang('no')}
                                        </label>
                                    </td>
                                </tr> -->
                                     <tr>
                                        <td>{:lang("classify")}<span class="required"></span></td>
                                        <td>
                                            {if isset($detail)}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="{$detail.drank}" >
                                                <input type="hidden"  name="olddrank" value="{$detail.drank}" >
                                            {else /}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="10">
                                            {/if}
                                        </td>
                                    </tr>
                            </tbody>
                    </table>
                </div>

                <div role="tabpanel" class="tab-pane" id="en" >
                        <table class="table table-striped table-hover ntTable" style="padding-top:0">
                                <tbody>
                                    <tr>
                                        <td>{:lang("top_rating")}<span class="required"></span></td>
                                        <td>
                                            <div class="input-group" style="width: 200px;">
                                                <select name="pclass_en" class="selectpicker"  data-live-search="true">
                                                    {if isset($catedata)}
                                                        <option value="0" selected>
                                                            {:lang("top_rating")}
                                                        </option>
                                                        {volist name="catedata" id="vo"}

                                                            {if isset($editParent_id) }
                                                                {if condition="$editParent_id eq $vo.id"}
                                                                    <option value="{$vo.id}" selected>
                                                                        {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_en)}
                                                                    </option>
                                                                {else /}
                                                                    <option value="{$vo.id}" >
                                                                        {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_en)}
                                                                    </option>
                                                                {/if}
                                                            {else /}
                                                                <option value="{$vo.id}" >
                                                                    {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_en)}
                                                                </option>
                                                            {/if}
                                                        {/volist}
                                                    {/if}

                                                    {notempty name="$addChild"}
                                                        <option value="{$addChild.id}">
                                                            {$addChild.name_en}
                                                        </option>
                                                    {/notempty}
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>{:lang("product_category_name")}<span class="required"></span></td>
                                        <td>
                                            {if isset($detail)}
                                                <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_en" value="{$detail.name_en}" data-id="{$detail.id}">
                                                <input type="hidden" class="classdid" name="clasdid_en" value="{$detail.id}">
                                            {else /}
                                                <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_en" value="">
                                            {/if}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>{:lang('status')}</td>
                                        <td  class="status">
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_en" value="1" {if isset($detail)}{if ($detail.status ==1)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if} > {:lang('normal')}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_en" value="3" {if isset($detail)}{if ($detail.status ==3)}checked{/if}{/if}> {:lang("hide")}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_en" value="4" {if isset($detail)}{if ($detail.status ==4)}checked{/if}{/if}> {:lang("off_the_shelf")}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_en" value="2" {if isset($detail)}{if ($detail.status ==2)}checked{/if}{/if}> {:lang('delete')}
                                            </label>
                                        </td>
                                    </tr>
                                  <!--   <tr>
                                        <td>{:lang('public')}</td>
                                        <td class="linkage">
                                            <label class="checkbox-inline">
                                                <input type="radio" name="general_en" value="1" {if isset($detail)}{if ($detail.is_public ==1)}checked{/if}{/if}> {:lang('yes')}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="general_en" value="2" {if isset($detail)}{if ($detail.is_public ==2)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if}> {:lang('no')}
                                            </label>
                                        </td>
                                    </tr> -->
                                     <tr>
                                        <td>{:lang("classify")}<span class="required"></span></td>
                                        <td>
                                            {if isset($detail)}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="{$detail.drank}" >
                                                <input type="hidden"  name="olddrank" value="{$detail.drank}" >
                                            {else /}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="10">
                                            {/if}
                                        </td>
                                    </tr>
                                </tbody>
                        </table>
                </div>

                <div role="tabpanel" class="tab-pane" id="pt">
                        <table class="table table-striped table-hover ntTable" style="padding-top:0">
                                <tbody>
                                    <tr>
                                        <td>{:lang("top_rating")}<span class="required"></span></td>
                                        <td>
                                            <div class="input-group" style="width: 200px;">
                                                <select name="pclass_pt" class="selectpicker"  data-live-search="true">
                                                    {if isset($catedata)}
                                                        <option value="0" selected>
                                                            {:lang("top_rating")}
                                                        </option>
                                                        {volist name="catedata" id="vo"}

                                                            {if isset($editParent_id) }
                                                                {if condition="$editParent_id eq $vo.id"}
                                                                    <option value="{$vo.id}" selected>
                                                                        {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_pt)}
                                                                    </option>
                                                                {else /}
                                                                    <option value="{$vo.id}" >
                                                                        {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_pt)}
                                                                    </option>
                                                                {/if}
                                                            {else /}
                                                                <option value="{$vo.id}" >
                                                                    {$vo.level|default=0|str_repeat='&emsp;',###*2}{:lang($vo.name_pt)}
                                                                </option>
                                                            {/if}
                                                        {/volist}
                                                    {/if}

                                                    {notempty name="$addChild"}
                                                        <option value="{$addChild.id}">
                                                            {$addChild.name_pt}
                                                        </option>
                                                    {/notempty}
                                                </select>
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>{:lang("product_category_name")}<span class="required"></span></td>
                                        <td>
                                            {if isset($detail)}
                                                <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_pt" value="{$detail.name_pt}" data-id="{$detail.id}">
                                                <input type="hidden" class="classdid" name="clasdid_pt" value="{$detail.id}">
                                            {else /}
                                                <input type="text" class="form-control clasname" placeholder="{:lang("product_category_name")}" name="clasname_pt" value="">
                                                <input type="hidden" class="classdid" name="clasdid_pt" value="">
                                            {/if}
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>{:lang('status')}</td>
                                        <td class="status">
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_pt" value="1" {if isset($detail)}{if ($detail.status ==1)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if}> {:lang('normal')}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_pt" value="3" {if isset($detail)}{if ($detail.status ==3)}checked{/if}{/if}> {:lang("hide")}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_pt" value="4" {if isset($detail)}{if ($detail.status ==4)}checked{/if}{/if}> {:lang("off_the_shelf")}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="status_pt" value="2" {if isset($detail)}{if ($detail.status ==2)}checked{/if}{/if}> {:lang('delete')}
                                            </label>
                                        </td>
                                    </tr>
                               <!--      <tr>
                                        <td>{:lang('public')}</td>
                                        <td class="linkage">
                                            <label class="checkbox-inline">
                                                <input type="radio" name="general_pt" value="1" {if isset($detail)}{if ($detail.is_public ==1)}checked{/if}{/if}> {:lang('yes')}
                                            </label>
                                            <label class="checkbox-inline">
                                                <input type="radio" name="general_pt" value="2" {if isset($detail)}{if ($detail.is_public ==2)}checked{/if}{/if} {if condition="$request == 'add'"}checked{/if}> {:lang('no')}
                                            </label>
                                        </td>
                                    </tr> -->
                                     <tr>
                                        <td>{:lang("classify")}<span class="required"></span></td>
                                        <td>
                                            {if isset($detail)}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="{$detail.drank}" >
                                                <input type="hidden" name="olddrank" value="{$detail.drank}" >
                                            {else /}
                                                <input type="text" class="form-control" placeholder="{:lang('classify')}" name="drank" value="10">
                                            {/if}
                                        </td>
                                    </tr>
                                </tbody>
                        </table>
                </div>
            </form>
        </div>
    </div>

    
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span>{:lang('cancel')}</button>
    <button type="button" class="btn btn-primary save" style="padding-left:24px;padding-right:24px"><span class="glyphicon glyphicon-floppy-disk"></span>{:lang('save')}</button>
</div>
<script>
$('.selectpicker').selectpicker({});
var state=true
$('.save').click(function(){
    if(state){
        state=false
        var modul={
            zh:getdata($('.formbox').serializeArray(),'zh'),
            en:getdata($('.formbox').serializeArray(),'en'),
            pt:getdata($('.formbox').serializeArray(),'pt')
        }
        if($('#ntModalLabel').attr('type') == 'edit'){
            var url = '/admin/procat/cateEdit?request=update';
        }else if($('#ntModalLabel').attr('type') == 'add' ){
            var url = '/admin/procat/cateAdd?request=insert';
        }
        console.log(modul)
        $.ajax({
            url:url,
            type:'post',
            data:modul,
            success:function(data){
                data = JSON.parse(data)
                if(data.status==1){
                    change_mes_type('.alert',data.status)
                    $('.alert').show()
                    $('.alert p').html('*'+data.msg+'<br>')
                    //toastr.info(data.msg)
                    $('#procat_editModal').modal('toggle')
                }else{
                    change_mes_type('.modal-body .alert',data.status)
                    $('.modal-body .alert').show()
                    $('.modal-body .alert p').html('*'+data.msg+'<br>')
                    //toastr.warning(data.msg);
                    state=true
                }
            }
        })
    }
})
function getdata(data,lange){
    var obj={
        'pclass':'',
        'clasname':{
            id:'',
            value:''
        },
        'status':'',
        general:''
    }
    data.forEach(element => {
        if(element.name=='pclass_'+lange){
            obj.pclass=element.value
        }
        if(element.name=='clasname_'+lange){
            obj.clasname.value=element.value
        }
        if(element.name=='clasdid_'+lange){
            obj.clasname.id=element.value
        }
        if(element.name=='status_'+lange){
            obj.status=element.value
        }
        if(element.name=='general_'+lange){
            obj.general=element.value
        }
        if(element.name=='drank'){
            obj.drank=element.value
        }
        if(element.name=='olddrank'){
            obj.olddrank=element.value
        }
    })
    return obj
}
$('.selectpicker').change(function(){
    var val=$(this).val()
    $('.selectpicker').selectpicker('val', val)
})
$('[name="drank"]').change(function(){
    var val=$(this).val()
    $('[name="drank"]').val( val)
})
$('.clasname').change(function(){
    var val=$(this).val()
    $('.clasname').val( val)
})
$('[name="olddrank"]').change(function(){
    var val=$(this).val()
    $('[name="olddrank"]').val( val)
})
$('.status input').change(function(){
            var val=$(this).val()
            $('.status input').each(function(index,item){
                if($(item).val()==val){
                    $(item).prop('checked',true)
                }else{
                    $(item).prop('checked',false)
                }
            })
        })
$('.linkage input').click(function(){
    var val= $(this).val()
    $('.linkage input').each((index,item)=>{
        if($(item).val()==val){
            $(item).prop('checked',true)
        }else{
            $(item).prop('checked',false)
        }
    })
})
</script>
